Skip to content

NPC_SetWeaponSkillLevel guard is inverted (doesn't do anything for valid skill ids) - #1298

Open
DignitySAMP wants to merge 2 commits into
openmultiplayer:masterfrom
DignitySAMP:fix/npc-weapon-skill
Open

DignitySAMP wants to merge 2 commits into
openmultiplayer:masterfrom
DignitySAMP:fix/npc-weapon-skill

Conversation

@DignitySAMP

Copy link
Copy Markdown

I encountered a problem with NPC's where NPC_SetWeaponSkillLevel wouldn't actually set the skill level. My intent was for NPC's to hold pistols in a single hand. I noticed that NPC_GetWeaponSkillLevel returns 999 despite valid code:

new npc = NPC_Create("SkillTest");
NPC_Spawn(npc);
NPC_SetWeapon(npc, WEAPON_COLT45);
NPC_SetWeaponSkillLevel(npc, WEAPONSKILL_PISTOL, 200);
printf("%d", NPC_GetWeaponSkillLevel(npc, WEAPONSKILL_PISTOL));

Expected: 200
Actual: 999

It seems this is the cause:

void NPC::setWeaponSkillLevel(PlayerWeaponSkill weaponSkill, int level)
{
if (weaponSkill >= 11 || weaponSkill < 0)

if (weaponSkill >= 11 || weaponSkill < 0)

Looking at getWeaponSkillLevel, the check in setWeaponSkillLevel is inverted and should be weaponSkill >= 0 && weaponSkill < 11. The first commit in this PR addresses that.

While testing this I also noticed NPC's on the default skill (999) have two guns, which is valid, but the server still counts it as a single mag which plays the short reload for them. This makes them start shooting again before the reload animation is done.

isWeaponDoubleHanded currently checks skillLevel > 999 while the client already dual wields at 999. The second commit changes that to >= 999.

A Colt 45 on 999 then goes from clip 17 / reload 1300 ms to clip 34 / reload 2000 ms. Also tested and confirmed the fix with the sawn-off, Micro Uzi and Tec-9.

I ran this on 1.6.7.3218 master and tested/fixed it on an empty server with a 0.3.7-R1 client (CachyOS, arch btw).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant